package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelPageVo;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "护理等级管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/nursingLevel")
public class NursingLevelcontroller extends BaseController {

    private final NursingLevelService nursingLevelService;

    @ApiOperation("查询所有护理等级")
    @GetMapping("/listAll")
    public ResponseResult<List<NursingLevelVo>> listAll() {
        List<NursingLevelVo> list = nursingLevelService.listAll();
        return ResponseResult.success(list);
    }

    @ApiOperation("条件分页查询护理等级")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelPageVo>> listByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status) {

        PageResponse<NursingLevelPageVo> page = nursingLevelService.listByPage(pageNum, pageSize, name, status);
        return success(page);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理等级详情")
    public ResponseResult<NursingLevelPageVo> getById(@PathVariable Long id) {
        NursingLevelPageVo nursingLevelPageVo = nursingLevelService.getById(id);
        return success(nursingLevelPageVo);
    }

    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult add(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.add(nursingLevelDto);
        return success();
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult delete(@PathVariable Long id){
        nursingLevelService.deleteById(id);
        return success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult startAndStop(@PathVariable Long id, @PathVariable Integer status){
        nursingLevelService.updateByIdAndStatus(id,status);
        return success();
    }
}
